class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        vector<int> copy = nums;
        sort(nums.begin(), nums.end());
        int left = 0;
        int right = nums.size() - 1;
        while (left != right) {
            if (nums[left] + nums[right] == target)
                break;
            else if (nums[left] + nums[right] > target)
                right--;
            else
                left++;
        }
        vector<int> res(2, -1);
        for (int i = 0; i < copy.size(); ++i) {
            if (copy[i] == nums[left] && res[0] == -1) {
                res[0] = i;
            }
            else if (copy[i] == nums[right]) {
                res[1] = i;
            }
        }
        return res;
    }
};